#!/bin/sh
#
# mongodb this script starts and stops the mongodb daemon
#
# chkconfig: 345 85 15
# description: MongoDB is a non-relational database storage system.
# processname: mongodb
# config: /usr/local/mongodb/conf.d/
# pidfile: /usr/local/mongodb/mongodb.pid

PATH=/usr/local/mongodb/bin:/sbin:/bin:/usr/sbin:/usr/bin
lock=/data/mongodb/data/mongod.lock
# var mongodb pid
pid=`ps -o pid,command ax | grep mongodb | awk '!/awk/ && !/\/bin\/sh/ && !/grep/ && !/tail/ {print $1}'`;
NAME=mongodb
test -x $DAEMON || exit 0
set -e
#
# See how we were called.
case "$1" in
   start)
      # Start daemons.
      if [ "${pid}" != "" ]; then
         echo -n "MongoDB already start. "
      else
         echo -n "Starting mongoDB: "
         /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf.d/mongodb.conf
      fi
      echo "${pid}"
      ;;
   stop)
      # Stop daemons.
      echo -n "Stopping MongoDB... "
      if [ "${pid}" != "" ]; then
         kill -2 ${pid};
         rm -rf ${lock}
      fi
      ;;
   restart)
      $0 stop
      $0 start
      ;;
   esac

exit 0
